﻿using BCCommon.Enums;
using BCData.WeChatComponent.WeChatMessageRecord;
using BCEntity.WeChatComponent.WeChatMessageRecord;
using System;
using System.Collections.Generic;
using System.Text;
using WeChatSDK.WeChatDto.Conversation.ReceivingMessage;

namespace BCService.WeChatComponent.WeChatHandleService
{
    /// <summary>
    /// 微信图片消息处理
    /// </summary>
    public class ImageMessageService : IWeChatMessageHandle
    {
        private readonly IWeChatMessageRecordData weChatMessageRecordData;

        public ImageMessageService(IWeChatMessageRecordData weChatMessageRecordData)
        {
            this.weChatMessageRecordData = weChatMessageRecordData;
        }

        public string HandleMessage(ReceivingMessageDto message)
        {
            ImageMessageDto imageMessageDto = (ImageMessageDto)message;
            WeChatMessageRecordEntity weChatMessageRecordEntity = this.RecordReceivingMessage(imageMessageDto);
            string response = "success";
            return response;
        }

        private WeChatMessageRecordEntity RecordReceivingMessage(ImageMessageDto imageMessageDto)
        {
            WeChatMessageRecordEntity entity = new WeChatMessageRecordEntity()
            {
                ToUserName = imageMessageDto.ToUserName,
                FromUserName = imageMessageDto.FromUserName,
                MessageType = WeChatMessageType.Image,
                MessageId = imageMessageDto.MsgId,
                MediaId = imageMessageDto.MediaId,
                PicUrl = imageMessageDto.PicUrl,
                IsReply = false
            };
            return this.weChatMessageRecordData.Add(entity);
        }
    }
}
